home *** CD-ROM | disk | FTP | other *** search
- /*
- HTML Form Parser 1.0b3
- ----------------------
-
- Written by Niel M. Bornstein
- Copyright © 1996 PLR Software, Inc.
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2 of the License, or (at your
- option) any later version.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include "Parser.h"
-
- void
- parser(
- Handle iBuffer,
- Handle oBuffer )
- {
- char c;
- long i, j = 0;
- long offset = 0;
- long s;
-
- s = GetHandleSize( iBuffer );
-
- for( i = 0; i < s; i++, j++ ) {
- switch( (*iBuffer)[i] ) {
- case '+':
- (*oBuffer)[j] = ' ';
- break;
- case '%':
- c = HexToChar( &(*iBuffer)[i] );
- if( c == '\n' ) c = '\r';
- (*oBuffer)[j] = c;
- i += 2;
- break;
- case '&':
- (*oBuffer)[j] = '\r';
- break;
- case '\r':
- case '\n':
- case '\t':
- i++;
- break;
- default:
- (*oBuffer)[j] = (*iBuffer)[i];
- break;
- }
- }
-
- SetHandleSize( oBuffer, j );
-
- return;
- }
-
- char
- HexToChar(
- char *h )
- {
- static hextable mytab[] = { { '0', 0 }, { '1', 1 }, { '2', 2 }, { '3', 3 },
- { '4', 4 }, { '5', 5 }, { '6', 6 }, { '7', 7 }, { '8', 8 }, { '9', 9 },
- { 'A', 10 }, { 'B', 11 }, { 'C', 12 }, { 'D', 13 }, { 'E', 14 }, { 'F', 15 },
- { 'a', 10 }, { 'b', 11 }, { 'c', 12 }, { 'd', 13 }, { 'e', 14 }, { 'f', 15 },
- { '\0', 0 } };
-
- char c1 = 0, c2 = 0, c;
- hextable *t = mytab;
-
- while ( t->c != '\0' ) {
- if ( t->c == *(h+1) ) c1 = t->x;
- if ( t->c == *(h+2) ) c2 = t->x;
- t++;
- }
- c = c1 * 16 + c2;
-
- return c;
- }
-
- /*
- Alternative way to do it suggested by johns@efn.org (John Selhorst). I
- opted for the table because I like tables. I hate to assume anything
- about the order of ascii characters (probably silly of me). Also, I
- didn't want to use ANSI functions (like sprintf and getc) because this
- is going in a teeny little code resource.
-
- char
- HexToChar(
- char *h )
- {
- unsigned char cin = h[1], cout;
-
- if (cin >= '0' && cin <= '9')
- cout = cin - '0';
- else if (cin >= 'A' && cin <= 'F')
- cout = cin - 'A' + 10;
- else if (cin >= 'a' && cin <= 'f')
- cout = cin - 'A' + 10;
- else
- cout = 0;
-
- cin = h[2];
- if (cin >= '0' && cin <= '9')
- cout += cin - '0';
- else if (cin >= 'A' && cin <= 'F')
- cout += cin - 'A' + 10;
- else if (cin >= 'a' && cin <= 'f')
- cout += cin - 'A' + 10;
- return cout;
- }
- */
-